
// 1. type 自定义类型【重要】
interface ITodo {
    id: number;
    title: string;
    isDone: boolean;
}
// 自定义一个类型
type ITodos = ITodo[];

const todos: ITodos = [
    {
        id: 1,
        title: '吃饭',
        isDone: false
    },
    {
        id: 2,
        title: '睡觉',
        isDone: true
    }
]

//2. 获取某个变量的类型
let me: string = '尚硅谷';
type SchoolType = typeof me;//  获取某个变量的类型

// let str:SchoolType = 123;


//3. 获取接口键名的联合类型[keyof 了解]
interface Person{
    name:string;
    age:number
}

function getInfo(obj: Person, key: keyof Person): number {
    console.log(obj[key]);
    return 123;
}
getInfo({name:'atguigu',age:19}, 'name')
// getInfo({name:'atguigu',age:19}, 'sex')// error


//4. 获取函数的返回值类型[掌握]
type retType = ReturnType<typeof getInfo>;

//5. 获取函数参数类型. 返回类型为『元组』类型 [了解]
type paramsType = Parameters<typeof getInfo>

//6. 获取接口属性的类型
let me123:Person['name']; //这里等效于 string



export {}



